package JavaCore.streams;

import java.io.IOException;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/**
 *
 */
public class ConvertStreams {

	public static void main(String[] args) throws IOException {
		String context = new String(Files.readAllBytes(Paths.get("C:\\Users\\Administrator\\Desktop\\�½��ı��ĵ�.txt")),
				StandardCharsets.UTF_8);
		List<String> words = Arrays.asList(context.split("\\PL+"));

		Stream<String> longWords = words.stream().filter(w -> w.length() > 5);

		Stream<String> lowercaseWors = words.stream().map(String::toUpperCase);

		Stream<String> firstLetters = words.stream().map(s -> s.substring(0, 1));

		Stream<Stream<String>> result = words.stream().map(m -> letters(m));

		Stream<String> flatResult = words.stream().flatMap(m -> letters(m));

		Stream<Double> randoms = Stream.generate(Math::random).limit(100);

		Stream<BigInteger> bigIntegerSkip = Stream.iterate(BigInteger.ZERO, n -> n.add(BigInteger.ONE)).limit(100)
				.skip(10);

		Stream<String> concat = Stream.concat(letters("Hello"), letters("world"));

		Stream<String> distinct = letters("hello").distinct();
	}

	public static Stream<String> letters(String s) {
		List<String> list = new ArrayList<>();
		for (char c : s.toCharArray()) {
			list.add(String.valueOf(c));
		}
		return list.stream();
	}

}
